home *** CD-ROM | disk | FTP | other *** search
- Path: cscsun3.larc.nasa.gov!hook
- From: hook@cscsun3.larc.nasa.gov (Ed Hook)
- Newsgroups: comp.lang.c
- Subject: Re: C beginner needs your help ASAP
- Date: 19 Feb 1996 15:09:12 GMT
- Organization: CSC/NASA Langley Research Center
- Distribution: world
- Message-ID: <4ga3qo$25l@reznor.larc.nasa.gov>
- References: <4g862f$p0b@risky.ecs.umass.edu> <Pine.A32.3.91.960218205210.105198F-100000@black.weeg.uiowa.edu>
- Reply-To: hook@cscsun3.larc.nasa.gov
- NNTP-Posting-Host: cscsun3.larc.nasa.gov
-
- In article <Pine.A32.3.91.960218205210.105198F-100000@black.weeg.uiowa.edu>, The Amorphous Mass <robinson@blue.weeg.uiowa.edu> writes:
- |> On Sun, 18 Feb 1996 sebag@ecs.umass.edu wrote:
- |>
- |> > I am a new C programmmer who desperately needs help.
- |> > I have been digging in the manuals for a way to do this but have still
- |> > come out empty handed. Here is the problem: I want to open files in a while
- |> > loop with different filenames. data0,data1,data2,data3, .. data1000 , ...
- |> > I need to increment an integer each time around then convert it to a string
- |> > and then somehow use strcat to combine the "data" with the integer string.
- |> > After that use fopen(filename, "a");
- |>
- |> Assuming proper #inclusions and variable declarations, etc.:
- |>
- |> for (i = 0; i != 1000; ++i) {
- |> sprintf(filename, "data%d", i);
- |> fopen(filename, "a");
-
- It might be more useful to code this as:
-
- if ((fp=fopen(filename,"a")) == NULL ) {
- /* deal with error */
- }
-
- since then there would be some way to _actually_ write to the
- file. Also, since there's never been any mention of closing any
- of these files, 'fopen()' _will_ eventually fail, so the error
- checking is not simply _pro_forma_
-
- |> /* ... */
- |> }
- |>
- |> will open files data0 ... data999. sprintf() is a wonderful thing. :)
- |>
- |> Posted and emailed.
- |>
- |>
- |> - James "Good candidates for exceptions are situations
- |> james-robinson@uiowa.edu that do not occur under normal circumstances."
- |> -- Kevin J. Hopps
-
- --
- Ed Hook | Coppula eam, se non posit
- Computer Sciences Corporation | acceptera jocularum.
- NASA Langley Research Center | Me? Speak for my employer?...<*snort*>
- Internet: hook@cscsun3.larc.nasa.gov | ... Get a _clue_ !!! ...
-